/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: XMQ
 * Date: 2022-06-17
 * Time: 18:03
 */
class Fruit{}
class Apple extends  Fruit{}
class Banana extends Fruit{}
class AppleA extends Apple{}
class AppleB extends Apple{}

class Message<T>{
    private T message;
    public T getMessage(){
        return message;
    }
    public void setMessage(T message){
        this.message = message;
    }
}
class MyArray<T>{
    public T[] array = (T[]) new Object[3];

    public void setVal(int pos, T val){
        array[pos] = val;
    }
    public T getVal(int pos){
        return array[pos];
    }

}
public class TestDemo1 {
    public static void main(String[] args) {
        Integer ig = 127;//自动装箱
        int it = ig; //自动拆箱
        int it2 = ig.intValue();//手动拆箱
        Integer ig2 = Integer.valueOf(10);//手动装箱
    }
    public static void main2(String[] args) {
        Message<Fruit> message = new Message<>();
        message.setMessage(new AppleA());
//        func1(message);
        func2(message);

        Message<Apple> message1 = new Message<>();
        message1.setMessage(new AppleB());
//        func1(message1);
        func2(message1);
    }
    public static void func2(Message<? super Apple> message){
        message.setMessage(new AppleA());
        message.setMessage(new AppleB());
    }
    public static void func1(Message<? extends Apple> message){
        Apple a = message.getMessage();
//        message.setMessage(new AppleB());
    }
    public static void main1(String[] args) {
        MyArray<Integer> array = new MyArray<>();
        array.setVal(0,10);
        func(array);

        MyArray<String> array1 = new MyArray<>();
        array1.setVal(0,"刘宇豪");
        func(array1);
    }
    public static void func(MyArray<?> message){
        Object i = message.getVal(0);
        System.out.println(message.getVal(0));
    }
}
